CC := gcc
CFLAGS := -std=gnu99 -Wall
OPT := -O3
# OPT += -ftree-vectorizer-verbose=8
# OPT += -msse
# OPT += -msse2
# OPT += -msse3
# OPT += -msse4a
# OPT += -mmmx
# OPT += -m3dnow
# OPT += -ftree-loop-distribution
# OPT += -march=native
# OPT += -funsafe-math-optimizations
# OPT += -funroll-loops
# OPT += -fstrict-aliasing
# OPT += -ftree-slp-vectorize
# OPT += -fbuiltin
# OPT += -fassociative-math 
# OPT += -ffast-math
# OPT += -fno-signed-zeros
# OPT += -fno-trapping-math
# OPT += -funroll-all-loops
# OPT += -fprofile-arcs -ftest-coverage

SRCS := $(wildcard *.c)
HDRS := $(wildcard *.h)

# We have 2 targets; a main target and a test target for testing
MAIN_TARGET := main
TEST_TARGET := test

# These are the source files common to both test and main target. 
# (none of these contain a main function)
COMMON_SRCS := util.c
COMMON_SRCS += matrix.c

# A main function for testing things
TEST_SRCS := test.c
TEST_SRCS += $(COMMON_SRCS)

# The real target
MAIN_SRCS := main.c
MAIN_SRCS += $(COMMON_SRCS)

TEST_OBJS = $(TEST_SRCS:.c=.o)
MAIN_OBJS = $(MAIN_SRCS:.c=.o)


%.o : %.c $(HDRS) 
	$(CC) $(CFLAGS) $(OPT) -c $< -o $@

all: $(MAIN_TARGET) $(TEST_TARGET)

$(TEST_TARGET): $(TEST_OBJS)
	$(CC) $(LDFLAGS) -o $@ $(TEST_OBJS)

$(MAIN_TARGET): $(MAIN_OBJS)
	$(CC) $(LDFLAGS) -o $@ $(MAIN_OBJS)


clean:
	rm -f testdata/* *.o $(MAIN_TARGET) $(TEST_TARGET) gpu
